<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>Document</title>
    <link rel="stylesheet" href="index.css">
    <!-- <link rel="stylesheet" href="index.js"> -->
</head>

<body>
    <div class="container">
        <h1>距离亲爱的生日到来还有：</h1>
        <ul>
            <li>
                <span id="day"></span>
                <sub>天</sub>
            </li>
            <li>
                <span id="hour"></span>
                <sub>时</sub>
            </li>
            <li>
                <span id="min"></span>
                <sub>分</sub>
            </li>
            <li>
                <span id="sec"></span>
                <sub>秒</sub>
            </li>
        </ul>
    </div>









    <script src="jquery.js"></script>

    <script>
        function $(id) {
            return typeof id === 'string' ? document.getElementById(id) : id;
        }

        /**
             * [checkTime description]
             */
        function checkTime(i) {
            if (i < 10) {
                i = "0" + i;
            }
            return i;
        }

        /**
             * [showTime description]
             * @return {[type]} [展示时间]
             */
        function showTime() {
            var curtime = new Date(); //当前时间
            var endtime = new Date("2019/3/12,00:00:00"); //目标时间
            var leftTime = (endtime.getTime() - curtime.getTime()) / 1000; //毫秒(ms)
            var leftDay = parseInt(leftTime / (24 * 60 * 60)); //剩余天数
            var leftHour = parseInt(leftTime / (60 * 60) % 24); //剩余小时
            var leftMin = parseInt(leftTime / 60 % 60); //剩余分钟
            var leftSec = parseInt(leftTime % 60); //剩余秒
            $('day').innerHTML = checkTime(leftDay);
            $('hour').innerHTML = checkTime(leftHour);
            $('min').innerHTML = checkTime(leftMin);
            $('sec').innerHTML = checkTime(leftSec);
            if (leftTime <= 0) {
                $('title').innerHTML = "再见2018，2019你好";
                $('day').innerHTML = 0;
                $('hour').innerHTML = 0;
                $('min').innerHTML = 0;
                $('sec').innerHTML = 0;
            }
            setTimeout(showTime, 1000);
        }
        showTime();
        </script>
</body>

</html>